<template>
  <div class="page-container">
    <el-card>
      <template #header>
        <div class="card-header">
          <span>资产列表</span>
          <el-button type="primary" @click="handleAdd">新增资产</el-button>
        </div>
      </template>

      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="id" label="ID" width="80" />
        <el-table-column prop="assetCode" label="资产编号" width="150" />
        <el-table-column prop="assetName" label="资产名称" />
        <el-table-column prop="assetType" label="资产类型" />
        <el-table-column prop="location" label="所在位置" />
        <el-table-column prop="status" label="状态">
          <template #default="{ row }">
            <el-tag :type="getStatusType(row.status)">
              {{ row.status }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="purchaseDate" label="采购日期" />
        <el-table-column label="操作" width="200">
          <template #default="{ row }">
            <el-button size="small" @click="handleEdit(row)">编辑</el-button>
            <el-button size="small" type="danger" @click="handleDelete(row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        v-model:current-page="currentPage"
        :page-size="10"
        :total="50"
        layout="total, prev, pager, next"
        style="margin-top: 20px; justify-content: flex-end;"
      />
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { ElMessage } from 'element-plus'

const currentPage = ref(1)

const tableData = ref([
  { id: 1, assetCode: 'AST-2024-001', assetName: '变压器A', assetType: '电力设备', location: '配电间1号', status: '运行中', purchaseDate: '2024-01-15' },
  { id: 2, assetCode: 'AST-2024-002', assetName: '开关柜B', assetType: '电力设备', location: '配电间2号', status: '运行中', purchaseDate: '2024-02-20' },
  { id: 3, assetCode: 'AST-2024-003', assetName: '监控设备C', assetType: '监控设备', location: '大楼A栋', status: '维修中', purchaseDate: '2024-03-10' },
  { id: 4, assetCode: 'AST-2024-004', assetName: '配电柜D', assetType: '电力设备', location: '配电间3号', status: '运行中', purchaseDate: '2024-04-05' },
  { id: 5, assetCode: 'AST-2024-005', assetName: '消防设备E', assetType: '消防设备', location: '大楼B栋', status: '待检修', purchaseDate: '2024-05-12' }
])

const getStatusType = (status) => {
  const map = {
    '运行中': 'success',
    '维修中': 'warning',
    '待检修': 'info',
    '已报废': 'danger'
  }
  return map[status] || 'info'
}

const handleAdd = () => {
  ElMessage.info('新增资产功能')
}

const handleEdit = (row) => {
  ElMessage.info(`编辑资产：${row.assetName}`)
}

const handleDelete = (row) => {
  ElMessage.warning(`删除资产：${row.assetName}`)
}
</script>

<style scoped>
.page-container {
  width: 100%;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
